﻿@model SAIM.Models.ListsViewModel
@using SAIM.Models
<div class="table-responsive">
    <table id="grid-list" class="table table-condensed table-hover">
        <thead>
            <tr>
                @foreach (string column in Model.ListStructure)
                {
                    if (column != "Id")
                    {
                        <th data-column-id="@column.Replace(" ", "")" data-identifier="true">@column</th>
                    }
                    else if (Model.ActualUser.DMLPermissions && Model.ActualUser.DMLPermissions)
                    {
                        <th data-column-id="@column.Replace(" ", "")" data-formatter="selection">Selección</th>
                    }
                }
            </tr>
        </thead>
        <tbody></tbody>
    </table>
</div>

<div id="modalList" class="modal fade" role="dialog">
    <div class="modal-dialog modal-lg">

        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title text-primary">Edición de lista</h4>
            </div>
            <div class="modal-body table-responsive">
                <dl class="dl-horizontal">
                    <dt>Nombre:</dt>
                    <dd>@Model.RealName</dd>
                </dl>
                @using(Html.BeginForm("EditList", "EVirtual", FormMethod.Post, new { @role = "form" }))
                {
                    @Html.AntiForgeryToken()
                    @Html.HiddenFor(m => m.Id)
                    @Html.HiddenFor(m => m.Delete)
                    <dl class="dl-horizontal">
                        <dt><label for="email">Usuarios:</label></dt>
                        <dd>
                            <div class="input-group">
                                <input type="text" class="form-control typeahead" placeholder="Buscar usuario..." autocomplete="off" />
                                <span class="input-group-btn">
                                    <button id="btn-addUser" class="btn btn-default" type="button">Agregar</button>
                                </span>
                            </div>
                        </dd>
                    </dl>
                    <dl class="dl-horizontal">
                        <dt></dt>
                        <dd>
                            <div class="table-responsive">
                                <table id="tableUsers" class="table table-condensed">
                                    <thead>
                                        <tr>
                                            <th>Usuario</th>
                                            <th>Información</th>
                                            <th>Estructura</th>
                                            <th>Eliminar usuario</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @{
                                            int count = 0; 
                                            foreach (UsersLists user in Model.Users)
                                            {
                                                if (Model.PrimaryUser != user.UserUPN)
                                                {
                                                    <tr class="user-items">
                                                        <td>
                                                            <input class="remove-user" name="Users[@count].Delete" value="false" type="hidden" />
                                                            <input name="Users[@count].UserUPN" value="@user.UserUPN" type="hidden" />
                                                            <input name="Users[@count].UserName" value="@user.UserName" type="hidden" />
                                                            <span>@user.UserName</span>
                                                        </td>
                                                        <td>
                                                            <input class="user-permission" name="Users[@count].DMLPermissions" type="checkbox" checked="@user.DMLPermissions" value="@user.DMLPermissions.ToString()"> Modificar
                                                        </td>
                                                        <td>
                                                            <input class="user-permission-adm" name="Users[@count].DDLPermissions" type="checkbox" checked="@user.DDLPermissions" value="@user.DDLPermissions.ToString()"> Modificar
                                                        </td>
                                                        <td class="text-center">
                                                            <button type="button" class="btn btn-default" title="Eliminar usuario"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button>
                                                        </td>
                                                    </tr>
                                                    count++;
                                                }
                                                else
                                                {
                                                    <tr>
                                                        <td>
                                                            <span>@user.UserName</span>
                                                        </td>
                                                        <td>Modificar</td>
                                                        <td>Modificar</td>
                                                        <td class="text-center">
                                                            <span class="badge progress-bar-danger"><span class="glyphicon glyphicon-ban-circle" aria-hidden="true"></span></span>
                                                        </td>
                                                    </tr>
                                                }
                                            }
}
                                    </tbody>
                                </table>
                            </div> 
                        </dd>
                    </dl>
                    <dl class="dl-horizontal">
                        <dt></dt>
                        <dd></dd>
                    </dl>
                    <dl class="dl-horizontal">
                        <dt></dt>
                        <dd>
                            <button id="updateList" type="submit" class="btn btn-primary">Editar</button>
                            <button id="deleteList" type="submit" class="btn btn-default">Eliminar</button>
                        </dd>
                    </dl>
                }
            </div>
        </div>

    </div>
</div>

<div id="modalCreateColumn" class="modal fade" role="dialog">
    <div class="modal-dialog modal-lg">
    </div>
</div>

@if(Model.ListStructure.Count > 0)
{ 
    <div id="modalEditColumn" class="modal fade" role="dialog">
        <div class="modal-dialog modal-lg">
            <div class="modal-content" style="overflow-x: auto;">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title text-primary">@SAIM.Resources.Site.EditColumn</h4>
                </div>
                <div class="modal-body table-responsive" style="min-height: 200px;">
                    @using (Html.BeginForm("EditColumn", "EVirtual", FormMethod.Post, new { @class = "form-horizontal", role = "form", @id = "EditColumnForm" }))
                    {
                        @Html.AntiForgeryToken()
                        @Html.Hidden("ListId", Model.Id)
                        @Html.Hidden("DeleteColumn", true)
                        <div class="form-group">
                            <label class="col-sm-3 control-label" for="email">@SAIM.Resources.Site.Column</label>
                            <div class="col-sm-9">
                                <select class="selectpicker form-control" name="ColumnName">
                                    @foreach (string column in Model.ListStructure)
                                    {
                                        if(column != "Id")
                                        { 
                                            <option>@column</option>
                                        }
                                    }
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-offset-3 col-sm-9" style="padding-top: 68px;">
                                <button id="EditColumnBtn" type="submit" class="btn btn-primary">@SAIM.Resources.Site.Delete</button>
                                <button type="button" class="btn btn-default" data-dismiss="modal">@SAIM.Resources.Site.Cancel</button>
                            </div>
                        </div>
                    }
                </div>
            </div>
        </div>
    </div>
}

<div id="modalAddItem" class="modal fade" role="dialog">
    <div class="modal-dialog modal-lg">
    </div>
</div>

<div id="modalEditItem" class="modal fade" role="dialog">
    <div class="modal-dialog modal-lg">
    </div>
</div>

<div id="modalUploadFile" class="modal fade" role="dialog">
    <div class="modal-dialog modal-lg">
    </div>
</div>
<script type="text/javascript">
    urlGetListData = "@Url.Action("GetListData")";
    urlAddColumn = '@Url.Action("_AddColumn", "EVirtual", new { listId = Model.Id })';
    urlAddItem = '@Url.Action("_AddItem", "EVirtual", new { listId = Model.Id })';
    urlEditItem = '@Url.Action("_EditItem", "EVirtual", new { listId = Model.Id })';
    urlUploadFile = '@Url.Action("_UploadFile", "EVirtual", new { listId = Model.Id })';
    itemCount = @Model.ListStructure.Count;
    ListId = '@Model.Id';
    hasDMLPermissions = '@Model.ActualUser.DMLPermissions';
</script> 
@if (Model.ActualUser.DDLPermissions)
{
    if (Model.ActualUser.DMLPermissions)
    {
        <script type="text/javascript">
            actions = '<div id=\"{{ctx.id}}\" class=\"{{css.header}}\"><div class=\"row\"><div class=\"col-md-7 list-header\">' +
                '<div class="btn-group" role="group" aria-label="Operaciones sobre la lista">' +
                    '<button type="button" class="btn btn-default" data-toggle="modal" data-target="#modalList" title=\"Editar lista\"><span class="fontelloicon icon-list-alt" aria-hidden="true"></span> <span class="fontelloicon  icon-pencil-1" aria-hidden="true"></span></button></div>\&nbsp\;\&nbsp\;\&nbsp\;' +
                '<div class="btn-group" role="group" aria-label="Operaciones sobre columnas">' +
                    '<button type="button" class="btn btn-default" title=\"Crear columna\" onclick="CreateColumn();"><span class="fontelloicon icon-columns" aria-hidden="true"></span> <span class="fontelloicon icon-plus-1" aria-hidden="true"></span></button>' +
                    (itemCount > 1 ? '<button type="button" class="btn btn-default" title=\"Editar columna\" onclick="EditColumn();"><span class="fontelloicon icon-columns" aria-hidden="true"></span> <span class="fontelloicon icon-pencil-1" aria-hidden="true"></span></button></div>\&nbsp\;\&nbsp\;\&nbsp\;' : '</div>\&nbsp\;\&nbsp\;\&nbsp\;') +
                '<div class="btn-group" role="group" aria-label="Operaciones sobre renglones">' +
                    (itemCount > 1 ? '<button type="button" class="btn btn-default" title=\"Nuevo elemento\" onclick="AddItem();"><span class="fontelloicon icon-list-2" aria-hidden="true"></span> <span class="fontelloicon icon-plus-1" aria-hidden="true"></span></button></div>' : '</div>') +
                ' </div><div style=\"padding: 0px 0px 5px 0px;\" class=\"col-md-5 text-right\"><p class=\"{{css.search}}\"></p><p class=\"{{css.actions}}\"></p></div></div></div>';
        </script>
    }
    else
    {
        <script type="text/javascript">
            actions = '<div id=\"{{ctx.id}}\" class=\"{{css.header}}\"><div class=\"row\"><div class=\"col-md-7 list-header\">' +
                '<div class="btn-group" role="group" aria-label="Operaciones sobre la lista">' +
                    '<button type="button" class="btn btn-default" data-toggle="modal" data-target="#modalList" title=\"Editar lista\"><span class="fontelloicon icon-list-alt" aria-hidden="true"></span> <span class="fontelloicon  icon-pencil-1" aria-hidden="true"></span></button></div>\&nbsp\;\&nbsp\;\&nbsp\;' +
                '<div class="btn-group" role="group" aria-label="Operaciones sobre columnas">' +
                    '<button type="button" class="btn btn-default" title=\"Crear columna\" onclick="CreateColumn();"><span class="fontelloicon icon-columns" aria-hidden="true"></span> <span class="fontelloicon icon-plus-1" aria-hidden="true"></span></button>' +
                    (itemCount > 1 ? '<button type="button" class="btn btn-default" title=\"Editar columna\"  onclick="EditColumn();"><span class="fontelloicon icon-columns" aria-hidden="true"></span> <span class="fontelloicon icon-pencil-1" aria-hidden="true"></span></button></div>' : '</div>') +
                ' </div><div style=\"padding: 0px 0px 5px 0px;\" class=\"col-md-5 text-right\"><p class=\"{{css.search}}\"></p><p class=\"{{css.actions}}\"></p></div></div></div>';
        </script>
    }
}
else
{
    if (Model.ActualUser.DMLPermissions)
    {
        <script type="text/javascript">
            actions = '<div id=\"{{ctx.id}}\" class=\"{{css.header}}\"><div class=\"row\"><div class=\"col-md-7 list-header\">' +
                '<div class="btn-group" role="group" aria-label="Operaciones sobre renglones">' +
                    (itemCount > 1 ? '<button type="button" class="btn btn-default" title=\"Nuevo elemento\" onclick="AddItem();"><span class="fontelloicon icon-list-2" aria-hidden="true"></span> <span class="fontelloicon icon-plus-1" aria-hidden="true"></span></button></div>\&nbsp\;\&nbsp\;\&nbsp\;</div>': '</div>') +
                '<div style=\"padding: 0px 0px 5px 0px;\" class=\"col-md-5 text-right\"><p class=\"{{css.search}}\"></p><p class=\"{{css.actions}}\"></p></div></div></div>';
        </script>
    }
    else
    {
        <script type="text/javascript">
            actions = '<div id=\"{{ctx.id}}\" class=\"{{css.header}}\"><div class=\"row\"><div class=\"col-md-7 list-header\"></div>' +
                '<div style=\"padding: 0px 0px 5px 0px;\" class=\"col-md-5 text-right\"><p class=\"{{css.search}}\"></p><p class=\"{{css.actions}}\"></p></div></div></div>';
        </script>
    }
}   
<script type="text/javascript" src="@Url.Content("~/Scripts/EVirtual/GetList.js")"></script>
